import request from '@/utils/request'

export function fetchList(query) {
  return request({
    url: '/system/sys/role/list',
    method: 'get',
    params: query
  })
}

export function fetchUsableRoleList() {
  return request({
    url: '/system/sys/role/usable/list',
    method: 'get'
  })
}

export function addRole(data) {
  return request({
    url: '/system/sys/role/add',
    method: 'post',
    data
  })
}

export function updateRole(data) {
  return request({
    url: '/system/sys/role/update',
    method: 'post',
    data
  })
}

export function deleteRole(id) {
  return request({
    url: '/system/sys/role/delete/' + id,
    method: 'post'
  })
}

export function fetchRoleMenu(roleId) {
  return request({
    url: '/system/sys/role/' + roleId + '/menu',
    method: 'get'
  })
}

export function fetchRolePermission(roleId) {
  return request({
    url: '/system/sys/role/' + roleId + '/permission',
    method: 'get'
  })
}

/**
 * 设置权限
 * @param roleId
 */
export function setMenu(data) {
  return request({
    url: '/system/sys/role/setMenu',
    method: 'post',
    data
  })
}
export function setPermission(data) {
  return request({
    url: '/system/sys/role/setPermission',
    method: 'post',
    data
  })
}

export function insertByUserId(userid, roleIds) {
  return request({
    url: '/system/upms/user/role/' + userid + '/insertByUserId',
    method: 'post',
    data: { roleIds }
  })
}

export function deleteByUserId(userid, roleIds) {
  return request({
    url: '/system/upms/user/role/' + userid + '/deleteByUserId',
    method: 'post',
    data: { roleIds }
  })
}

